using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Common;
using Net.SourceForge.WURFL.Core;

namespace Roaming.view
{
    public partial class index : System.Web.UI.Page
    {
        protected int cols = 0;
        protected DataSet dsIcon = null;
        protected DataSet dsTop = null;
        protected void Page_Load(object sender, EventArgs e)
        {
            string strUA = Request.Headers["USER-AGENT"].ToString();
            if (strUA.ToLower().Contains("opera"))
            {
                if (Request.Headers["X-OperaMini-Phone-UA"] != null)
                    strUA = Request.Headers["X-OperaMini-Phone-UA"].ToString();
            }
            cols = DAL.getColLinkSite(strUA);
            if (cols > 2)
            {
                cols = 3;
            }


            IWURFLManager wurflManager = WURFLManagerHolder.WURFLManager;
            //IDevice device = wurflManager.GetDeviceForRequest(strUA);
            if (!IsPostBack)
            {
                //update hit
                try
                {
                    DAL.ExecuteQuery("EXEC tblHitCounter_Update");
                }
                catch (Exception ex)
                {
                    throw (ex);
                }
                Common.DAL.FillDataToDropdownList(DdlCity, "tblCategory where parentid=336 order by oder asc", "categoryId,categoryName");

                if (Session["CityId"] == null || (string) Session["CityId"] == "")
                {
                    //DdlCity.SelectedIndex = 3;
                    //DdlCity.Items.FindByValue("3").Selected = true;
                    Session["CityId"] = DdlCity.SelectedValue;
                    Session["CityName"] = DdlCity.SelectedItem.Text;
                }
                else
                {
                    //DdlCity.SelectedValue = Session["CityId"].ToString();
                    DdlCity.Items.FindByValue(Session["CityId"].ToString()).Selected = true;
                }
                //Session["CityId"] = DdlCity.SelectedValue;
                //Session["CityName"] = DdlCity.SelectedItem.Text;
                //Session.Timeout = 60;

                BindData();
                BindDataTop();


            }
            //else
            //{
            //    BindData();
            //    BindDataTop();
            //    //Session["CityId"] = DdlCity.SelectedValue;
            //    //Session["CityName"] = DdlCity.SelectedItem;
            //}



        }
        protected void BindData()
        {
            string strSQL = "";
            if (cols == 2)
            {
                strSQL = string.Format("Select * from [tblCategory] where Ispriority=2 order by oder asc");
            }
            else
                strSQL = string.Format("tblCategory_GetAllByCateId {0},{1}", 0, 88);
            dsIcon = Common.DAL.GetDataSet(strSQL);

        }
        protected void BindDataTop()
        {
            string strSQL = "";
            if (cols == 2)
            {
                strSQL = string.Format("Select * from [tblCategory] where Ispriority=1 order by oder asc");
            }
            else
                strSQL = string.Format("Select * from [tblCategory] where ParentId =345 and Status=1");
            dsTop = Common.DAL.GetDataSet(strSQL);

        }
        protected void btn_go_click(object sender, EventArgs e)
        {
            Session.RemoveAll();
            string url = string.Format("/view/index.html");
            Session["CityId"] = DdlCity.SelectedValue;
            Session["CityName"] = DdlCity.SelectedItem.Text;
            Response.Redirect(url);
        }
    }
}
